import { createRouter, createWebHistory } from 'vue-router'
import routes from "@/router/routes";
import {getAccessToken} from "@/utils/auth";

const router = createRouter({
  history: createWebHistory(),
  routes: [...routes]
})

router.beforeEach((to, from, next) => {
  const token: any = getAccessToken()
  const whiteList = ['/snow/login.html', '/snow.html', '/snow/register.html']
  if(token) {
    next()
  } else {
    if(whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next('/snow/login.html')
    }
  }
})

export default router
